package com.linrui.gift.exception;

import com.linrui.gift.exception.code.ErrorCode;

import java.util.List;

public class GiftAssert {

    public final static String DEFAULT_MESSAGE = "非法请求！请重新输入";

    //为空报错
    public static void assertNotNull(Object object){
        if (object == null){
            throw new BusinessException(DEFAULT_MESSAGE);
        }
    }
    //为空报错
    public static void assertNotNull(Object object,String message){
        if (object == null){
            throw new BusinessException(message);
        }
    }
    //为空报错
    public static void assertNotNull(Object object, ErrorCode code){
        if (object == null){
            throw new BusinessException(code.getMassage(),code.getCode());
        }
    }
    //不为空报错
    public static void assertNull(Object object,String message){
        if (object != null){
            throw new BusinessException(message);
        }
    }
    //断言字符串不为blank
    public static void assertNotBlank(String str,String message){
        if (str == null ||str.trim().equals("")){
            throw new RuntimeException(message);
        }
    }
    //断言字符串为blank
    public static void assertBlank(String str,String message){
        if (str != null || !str.trim().equals("")){
            throw new RuntimeException(message);
        }
    }
    //对象为空报错
    public static void assertListNotNull(List<?> object, String message){
        if (object == null || object.size()<1){
            throw new BusinessException(message);
        }
    }
    //对象不为空报错
    public static void assertListNull(List<?> object, ErrorCode code){
        if (object == null && object.size()>0){
            throw new BusinessException(code.getMassage(),code.getCode());
        }
    }
    //对象不为空报错
    public static void assertListNull(List<?> object, String message){
        if (object != null && object.size()>0){
            throw new BusinessException(message);
        }
    }
    //对象为空报错
    public static void assertListNotNull(List<?> object, ErrorCode code){
        if (object != null || object.size()<1){
            throw new BusinessException(code.getMassage(),code.getCode());
        }
    }
    //对象为空报错
    public static void assertStrEq(String str1, String str2,String message){
        assertNotNull(str1, message);
        assertNotNull(str2, message);
        if (!str1.equals(str2)){
            throw new BusinessException(message);
        }
    }
    //对象为空报错
    public static void assertStrEq(String str1, String str2,ErrorCode code){
        assertNotNull(str1, code);
        assertNotNull(str2, code);
        if (!str1.equals(str2)){
            throw new BusinessException(code.getMassage(),code.getCode());
        }
    }
    //对象为空报错
    public static void assertStrNotEq(String str1, String str2,ErrorCode code){
        assertNotNull(str1, code);
        assertNotNull(str2, code);
        if (str1.equals(str2)){
            throw new BusinessException(code.getMassage(),code.getCode());
        }
    }
}
